//编辑帖子内容节点

var  mainmessage=$("#tiptest1");

//添加超链接
$("#linkAppear").click(function () {

    var currentTop = $(".mhy-action-sheet").css("top");
    if (currentTop === "0px") {
        $(".mhy-action-sheet").css("top", "100%");
    } else {
        $(".mhy-action-sheet").css("top", "0px");
    }
});


//实现链接框显示隐藏
$(".icon-close1").click(function () {
    $(".mhy-action-sheet").css("top", "100%");
});
$("#Cancel").click(function () {
    $(".mhy-action-sheet").css("top", "100%");
});
//显示文字颜色框
$(".mhy-toolbar-color").click(function () {
    var currentDisplay = $(".mhy-toolbar-color__wrap").css("display");
    if (currentDisplay === "none") {
        $(".mhy-toolbar-color__wrap").css("display", "block");
    }
});
document.addEventListener('DOMContentLoaded', function () {
    var colorList = document.getElementById('mhy-toolbar-color__list');
    var colorPreview1 = document.getElementById('appearDefaultC');
    var colorPreview2 = document.getElementById('appear-main');


    // 添加点击事件监听器
    colorList.addEventListener('click', function (event) {
        var target = event.target;
        // 确保点击的是<li>元素
        if (target.tagName.toLowerCase() === 'li') {
            // 获取点击元素的背景颜色
            var bgColor = window.getComputedStyle(target).backgroundColor;
            // 应用背景颜色到预览div
            colorPreview1.style.backgroundColor = bgColor;
            colorPreview2.style.backgroundColor = bgColor;
        }
        var previousDiv = document.getElementById('mhy-toolbar-color__wrap');
        setTimeout(function () {
            previousDiv.style.display = 'none';
        }, 500); // 延迟1000毫秒（1秒）
    });
});
$('.mhy-switch__track').on('click', function () {
    var $content = $(this).parent().parent(); // 找到最近的.parent()两次，以定位到.original-form-item__content
    if ($content.hasClass('mhy-switch--checked')) {
        $content.removeClass('mhy-switch--checked'); // 移除.chec类
    } else {
        $content.addClass('mhy-switch--checked'); // 添加.chec类
    }
});

//生成视频节点
var $videos = " <div class=\"mhy-video-frame ql-frame\" contenteditable=\"false\">" +
    "<iframe border=\"0\" frameborder=\"0\" framespacing=\"0\" scrolling=\"no\" allowfullscreen=\"true\" src=\"https://player.bilibili.com/player.html?bvid=&amp;autoplay=false\">" +
    "</iframe><div class=\"ql-blot-del\"></div></div>"

$("#faceAppear").click(function () {
    var currentDisplay = $(".editor-container__emoticon").css("display");
    if (currentDisplay === "none") {
        $(".editor-container__emoticon").css("display", "block");
    } else {
        $(".editor-container__emoticon").css("display", "none");
    }

})
//图片节点
var pictures = "<div class=\"ql-image-box\"><img preview=\"imgPreview\" src=\"https://upload-bbs.miyoushe.com/upload/2024/09/06/320964050/2f359472a72478b192681b7688de08e0_1855833738953334054.png?x-oss-process=image//resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,png\" large=\"https://upload-bbs.miyoushe.com/upload/2024/09/06/320964050/2f359472a72478b192681b7688de08e0_1855833738953334054.png?x-oss-process=image/auto-orient,0/interlace,1/format,png\" data-pswp-uid=\"1\"></div>";
//表情包节点
$(".mhy-emoticon__list > div").click(function(){
    var url = $(this).css('background-image');
    // 使用正则表达式移除 "url(" 和 ")"
    var pureUrl = url.replace(/^url\(["']?(.+?)["']?\)$/, '$1');
    //生成图片节点
    var pictures="<img  class=\"emoticon-image\" src=\""+pureUrl+"\" >";
    mainmessage.append(pictures)
    var currentDisplay = $(".editor-container__emoticon").css("display");
    if (currentDisplay === "none") {
        $(".editor-container__emoticon").css("display", "block");
    } else {
        $(".editor-container__emoticon").css("display", "none");
    }
});


var memes = "<img class=\"emoticon-image\" src=\"https://upload-bbs.mihoyo.com/upload/2022/11/14/829f0a1d533765b80769dd1a38dc338c_9182108590963360703.png\" data-name=\"阿姬惊讶\">"
//艾特用户
$(".mhy-toolbar-mention").click(function (){

    var currentDisplay = $(".mention-dialog__box").css("display");
    if (currentDisplay === "none") {
        $(".mention-dialog__box").css("display", "block");
    } else {
        $(".mention-dialog__box").css("display", "none");
    }
})
//超链接节点
$("#sure").click(function (){
    $(".mhy-action-sheet").css("top", "100%");

})
$("#textInput").focus(function (){
    $("#textInput").val('')
    }
)

$("#passImG").click(function (){
    $(".mhy-action-sheet1").css("top", "0%");
})
$("#closeImg").click(function (){
    $(".mhy-action-sheet1").css("top", "100%");
})

$("#pushPost").click(function (){

//获取发布帖子内容
    //主体部分
    var post_id;//帖子id
    var topic_ids=$("#myPostTopic").val();//所属话题id
    var uid;//用户id

    var subject=$("#pushtittle").val();//标题
    var content =$("#pushintroduce").val() //简介
    var message=$("#tiptest1").html();//帖子内容
    var cover;//题头图
    var created_at;//创建时间

    var is_official;//是否为官方1，是，0不是

    var  max_floor;//评论数量

    var is_original='1' ;//是否为原创

    var  clickCount;//点赞数

    $.ajax({
        url: "PushPostServlet",
        type: "post", // 显式指定请求类型为 POST
        data: {"topic_ids":topic_ids,"subject":subject,"content": content,"message":message,"is_original":is_original},
        dataType:"text",
        // dataType: "text", // 可选，如果服务器返回的是纯文本可以保留
        success: function(id) {
            if(id!=null){
                location.href="QueryPostDetail?id="+id+""
            }else {
                location.href="QueryAddPostTopicServlet"
            }
        },

    });
})






















